<!--
/**
* @name MapFiltrate
* @description 地图筛选
* @author wind-lc
* @date 2020-06-10
* @return {Object} search 搜索
* @example <map-filtrate @search=""></map-filtrate>
*/
-->
<template>
  <div class="data-monitor-map-filtrate">
    <div class="data-monitor-map-filtrate-search">
      <div class="data-monitor-map-filtrate-select"
           @mouseleave="filtrateSelect = false">
        <span>{{searchTypeText}}</span>
        <icon-svg @click.native="filtrateSelect = !filtrateSelect"
                  :class="{'data-monitor-map-filtrate-select-active':filtrateSelect}"
                  type="icon-below-line"></icon-svg>
        <transition name="slide-fade">
          <div v-show="filtrateSelect"
               class="data-monitor-map-filtrate-select-list">
            <ul>
              <li v-for="(item,index) in searchTypeList"
                  :key="index"
                  @click="filtrateSelectChange(item.value)">{{item.name}}</li>
            </ul>
          </div>
        </transition>
      </div>
      <input v-model="searchValue"
             type="text"
             placeholder="请输入企业名称"
             @keyup.enter="searchData">
      <span @click="searchData">搜索</span>
    </div>
    <div class="data-monitor-map-filtrate-filter"
         @mouseleave="filtrateFilter = false"
         @click="filtrateFilter = !filtrateFilter">
      <icon-svg type="icon-shaixuan"></icon-svg>
      <span>筛选</span>
      <transition name="slide-fade">
        <div v-show="filtrateFilter"
             class="data-monitor-map-filtrate-filter-list">
          <ul>
            <li v-for="(item,index) in filtrateFilterTypeList"
                :key="index"
                @click="filtrateFilterChange(item.value)">{{item.name}}</li>
          </ul>
        </div>
      </transition>
    </div>
  </div>
</template>
<script>
import IconSvg from '@/components/IconSvg'

export default {
  name: 'MapFiltrate',
  components: {
    IconSvg
  },
  data () {
    return {
      // 搜索值
      searchValue: '',
      // 搜索类型
      searchType: '0',
      // 搜索类型列表
      searchTypeList: [
        {
          value: '0',
          name: '全部'
        },
        {
          value: '1',
          name: '重点企业'
        },
        {
          value: '2',
          name: '我观注的企业'
        }
      ],
      // 搜索类型下拉隐藏显示
      filtrateSelect: false,
      // 筛选
      filtrateFilterType: '0',
      // 筛选列表
      filtrateFilterTypeList: [
        {
          value: '0',
          name: '按行业'
        },
        {
          value: '1',
          name: '按区域'
        }
      ],
      // 筛选下拉隐藏显示
      filtrateFilter: false
    }
  },
  computed: {
    searchTypeText () {
      let text = ''
      this.searchTypeList.forEach(el => {
        if (el.value === this.searchType) {
          text = el.name
        }
      })
      return text
    }
  },
  mounted () {
  },
  methods: {
    // 搜索数据
    searchData () {
      this.$emit('search', {
        type: '0',
        value: this.searchValue,
        Filter: ''
      })
    },
    // 搜索类型下拉
    filtrateSelectChange (value) {
      this.filtrateSelect = !this.filtrateSelect
      this.searchType = value
    },
    // 筛选类型下拉
    filtrateFilterChange (value) {
      this.filtrateFilter = !this.filtrateFilter
      this.filtrateFilterType = value
    }
  }
}
</script>
<style lang="scss">
.data-monitor-map-filtrate {
  position: absolute;
  top: 46px;
  right: 60px;
  z-index: 2;
  width: 590px;
  height: 50px;
  display: flex;
  justify-content: space-between;
}
.data-monitor-map-filtrate-search {
  width: 500px;
  height: 50px;
  background-color: rgba(0, 0, 0, 0.1);
  border-radius: 4px;
  display: flex;
  & > span {
    width: 70px;
    background-color: #1890ff;
    border-radius: 0 4px 4px 0;
    text-align: center;
    line-height: 50px;
    font-size: 16px;
    color: #ffffff;
    cursor: pointer;
  }
  input {
    border: none;
    outline: none;
    background-color: rgba(0, 0, 0, 0);
    width: 266px;
    font-size: 16px;
    padding: 0 12px;
  }
  ::-webkit-input-placeholder {
    color: #999999;
  }
  ::-webkit-input-placeholder {
    color: #999999;
  }

  ::-moz-placeholder {
    color: #999999;
  }

  :-ms-input-placeholder {
    color: #999999;
  }
}
.data-monitor-map-filtrate-select {
  width: 164px;
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  &::after {
    content: '';
    display: block;
    width: 1px;
    height: 22px;
    background-color: #999999;
    position: absolute;
    top: 50%;
    right: 0;
    margin-top: -11px;
  }
  span {
    color: #333333;
    font-size: 16px;
  }
  .icon-svg {
    color: #999999;
    cursor: pointer;
    font-size: 16px;
    transition: all ease 0.5s;
  }
  .data-monitor-map-filtrate-select-active {
    transform: rotate(180deg);
  }
  .data-monitor-map-filtrate-select-list {
    position: absolute;
    display: block;
    top: 50px;
    left: 0;
    width: 200px;
    padding-top: 9px;
    ul {
      padding: 10px 0;
      border-radius: 4px;
      background-color: rgba(0, 0, 0, 0.1);
      position: relative;
      &::before {
        content: '';
        display: block;
        position: absolute;
        top: -9px;
        left: 30px;
        border-bottom: 9px solid rgba(0, 0, 0, 0.1);
        border-left: 9px dashed transparent;
        border-right: 9px dashed transparent;
      }
      li {
        padding: 10px 20px;
        font-size: 16px;
        cursor: pointer;
        &:hover {
          background-color: rgba(0, 0, 0, 0.2);
          color: #ffffff;
        }
      }
    }
  }
}
.data-monitor-map-filtrate-filter {
  background-color: #1890ff;
  width: 73px;
  border-radius: 4px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  position: relative;
  .icon-svg {
    font-size: 18px;
    color: #ffffff;
    font-weight: bold;
  }
  span {
    font-size: 16px;
    color: #ffffff;
    margin-left: 6px;
  }
}
.data-monitor-map-filtrate-filter-list {
  position: absolute;
  top: 50px;
  right: 0;
  width: 200px;
  padding-top: 9px;
  ul {
    padding: 10px 0;
    border-radius: 4px;
    background-color: rgba(0, 0, 0, 0.1);
    position: relative;
    &::before {
      content: '';
      display: block;
      position: absolute;
      top: -9px;
      right: 32px;
      border-bottom: 9px solid rgba(0, 0, 0, 0.1);
      border-left: 9px dashed transparent;
      border-right: 9px dashed transparent;
    }
    li {
      padding: 10px 20px;
      font-size: 16px;
      cursor: pointer;
      &:hover {
        background-color: rgba(0, 0, 0, 0.2);
        color: #ffffff;
      }
    }
  }
}
.slide-fade-enter-active {
  transition: all 0.5s ease;
}
.slide-fade-leave-active {
  transition: all 0.5s cubic-bezier(1, 0.5, 0.8, 1);
}
.slide-fade-enter,
.slide-fade-leave-to {
  transform: translateX(10px);
  opacity: 0;
}
</style>
